<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="渠道名称" prop="tradeQudao">
        <el-input
          v-model="queryParams.tradeQudao"
          placeholder="请输入渠道名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付方式" prop="payWay">
        <el-select v-model="queryParams.tradeResult" placeholder="请选择支付方式" clearable size="small">
          <el-option v-for="item in tradeResults" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="对账批次" prop="batchNo">
        <el-input
          v-model="queryParams.batchNo"
          placeholder="请输入对账批次"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易金额" prop="amount">
        <el-input
          v-model="queryParams.amount"
          placeholder="请输入交易金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否差错" prop="hasDiff">
        <el-select v-model="queryParams.hasDiff" placeholder="请选择" clearable size="small">
          <el-option v-for="item in hasDiffs" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <div>
        <el-form-item label="交易日期">
          <div class="block">
            <el-date-picker
              v-model="queryParams.startTime"
              value-format="yyyy-MM-dd"
              type="date"
              clearable
              placeholder="选择日期时间">
            </el-date-picker>至
            <el-date-picker
              v-model="queryParams.endTime"
              value-format="yyyy-MM-dd"
              type="date"
              placeholder="选择日期时间"
              clearable>
            </el-date-picker>
          </div>
        </el-form-item>
      </div>
      <el-form-item label="处理结果" prop="processState">
        <el-select v-model="queryParams.processState" placeholder="请选择" clearable size="small">
          <el-option v-for="item in processStates" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="支付方式" prop="payWay">
        <el-select v-model="queryParams.payWay" placeholder="请选择支付方式" clearable size="small">
          <el-option v-for="item in payWaies" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="checkBatchDetailList" @selection-change="handleSelectionChange">
<!--      <input type="hidden" name="batchNo" value="${batch.batchNo!''}">-->
<!--      <input type="hidden" name="checkDay" value="${batch.checkDay!''}">-->
      <el-table-column
        prop="batchNo"
        label="对账批次"
        width="120">
      </el-table-column>
      <el-table-column
        prop="payOrderNo"
        label="交易流水号"
        width="200">
      </el-table-column>
      <el-table-column
        prop="qudaoOrderNo"
        label="渠道订单号"
        width="250">
      </el-table-column>
      <el-table-column
        prop="tradeQudao"
        label="渠道名称">
        <span>拉卡拉</span>
      </el-table-column>
      <el-table-column
        label="交易结果">
        <template slot-scope="scope">
          <span v-if="scope.row.tradeResult==1">处理中</span>
          <span v-if="scope.row.tradeResult==2">成功</span>
          <span v-if="scope.row.tradeResult==3">失败</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="amount"
        label="交易金额">
      </el-table-column>
      <el-table-column
        prop="tradeDateZf"
        label="交易日期"
        width="105">
      </el-table-column>
      <el-table-column
        prop="commissionFee"
        label="手续费">
      </el-table-column>
      <el-table-column
        label="支付方式">
        <template slot-scope="scope">
          <span v-if="scope.row.payWay=='1'">微信支付</span>
          <span v-if="scope.row.payWay=='2'">支付宝扫码</span>
          <span v-if="scope.row.payWay=='3'">微信公众号</span>
          <span v-if="scope.row.payWay=='4'">认证支付</span>
          <span v-if="scope.row.payWay=='5'">代付到银行卡</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="tradeAccount"
        label="交易账号">
      </el-table-column>
      <el-table-column
        label="交易账户类型">
        <template slot-scope="scope">
          <span v-if="scope.row.tradeAccountType=='1'">微信</span>
          <span v-if="scope.row.tradeAccountType=='2'">支付宝</span>
          <span v-if="scope.row.tradeAccountType=='3'">银行卡</span>
          <span v-if="scope.row.tradeAccountType=='4'">拉卡拉</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="checkEndDate"
        label="对账完成时间"
        width="100">
      </el-table-column>
      <el-table-column
        label="是否差错">
        <template slot-scope="scope">
          <span v-if="scope.row.hasDiff=='0'">否</span>
          <span v-if="scope.row.hasDiff=='1'">是</span>
        </template>
      </el-table-column>
      <el-table-column
        label="处理结果">
        <template slot-scope="scope">
          <span v-if="scope.row.processState=='1'">未处理</span>
          <span v-if="scope.row.processState=='2'">要结算</span>
          <span v-if="scope.row.processState=='3'">不结算</span>
          <span v-if="scope.row.processState=='4'">已处理</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <el-button
            v-if="scope.row.hasDiff==true && scope.row.processState==1"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['financing:checkBatchDetail:edit']"
          >差错处理</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />



  </div>
</template>

<script>
import { listcheckBatchDetail, getcheckBatchDetail, delcheckBatchDetail, addcheckBatchDetail, updatecheckBatchDetail } from "@/api/finance/detail";

export default {
  name: "checkBatchDetail",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //交易结果：接口回调或者返回的结果 1:处理中，2:成功，3:失败。
      tradeResults:[
        {label:"处理中",value:"1"},
        {label:"成功",value:"2"},
        {label:"失败",value:"3"}
      ],
      //支付方式,同流水里面一样 1:微信扫码，2:支付宝扫码，3:微信公众号，4:认证支付，5:代付到银行卡
      payWaies:[
        {label:"微信扫码",value:"1"},
        {label:"支付宝支付",value:"2"},
        {label:"微信公众号",value:"3"},
        {label:"认证支付",value:"4"},
        {label:"代付到银行卡",value:"5"}
      ],
      //是否差错
      hasDiffs:[
        {label:"否",value:"0"},
        {label:"是",value:"1"},
      ],
      //处理结果
      processStates:[
        {label:"未处理",value:"1"},
        {label:"要结算",value:"2"},
        {label:"不结算",value:"3"},
        {label:"已处理",value:"4"},
      ],
      // 楼盘信息表格数据
      checkBatchDetailList: [
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询楼盘信息列表 */
    getList() {
      this.loading = true;
      listcheckBatchDetail(this.queryParams).then(response => {
        this.checkBatchDetailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        outsideId: null,
        name: null,
        province: null,
        city: null,
        county: null,
        commercialArea: null,
        subway: null,
        address: null,
        proportion: null,
        grossPlotRatio: null,
        greenCoverage: null,
        buildingCount: null,
        efficiency: null,
        developer: null,
        estate: null,
        introduce: null,
        communityType: null,
        buildingType: null,
        premisesType: null,
        updateTime: null,
        longItude: null,
        latItude: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加楼盘信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getcheckBatchDetail(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改楼盘信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatecheckBatchDetail(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addcheckBatchDetail(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除楼盘信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delcheckBatchDetail(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('financing/checkBatchDetail/export', {
        ...this.queryParams
      }, `financing_checkBatchDetail.xlsx`)
    }
  }
};
</script>
